package com.chenglu.android.common.utils;

import android.os.CountDownTimer;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.chenglu.android.R;
import com.chenglu.android.common.base.Global;


/**
 * @Author liao on 2017/11/6.
 */

public class CountDownTimerUtils extends CountDownTimer {
   private TextView button;

    /**
     * @param millisInFuture    The number of millis in the future from the call
     *                          to {@link #start()} until the countdown is done and {@link #onFinish()}
     *                          is called.
     * @param countDownInterval The interval along the way to receive
     *                          {@link #onTick(long)} callbacks.
     */
    public CountDownTimerUtils(TextView btn, long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);
        this.button = btn;
    }

    @Override
    public void onTick(long millisUntilFinished) {
        button.setClickable(false); //设置不可点击  后可重新发送
        button.setText(millisUntilFinished / 1000 + "秒");  //设置倒计时时间
        button.setTextColor(ContextCompat.getColor(Global.mContext,R.color.color_setting_phone_text));
//        button.setBackgroundResource(R.drawable.shape_square_bg_press); //设置按钮为灰色，这时是不能点击的

    }

    @Override
    public void onFinish() {
        button.setText("获取验证码");
        button.setClickable(true);//重新获得点击
        button.setTextColor(ContextCompat.getColor(Global.mContext,R.color.color_agreement));
//        button.setBackgroundResource(R.drawable.shape_square_bg_green);  //还原背景色
    }



}
